import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Profile } from '../entities/profile.entity';
import { IsArray, IsBoolean, IsEmail, IsNotEmpty, IsOptional, IsString, Length } from 'class-validator';

/** 添加用户 */
export class CreateUserDto {
  @ApiProperty({ description: '用户名', example: 'admin' })
  @IsString()
  @IsNotEmpty({ message: '用户名不能为空' })
  @Length(6, 20, { message: `用户名长度必须大于6位小于20位` })
  username: string;

  @ApiProperty({ description: '密码' })
  @IsString()
  @IsNotEmpty({ message: '密码不能为空' })
  @Length(6, 20, { message: '密码长度必须大于6位小于20位' })
  password: string;

  @ApiPropertyOptional({ description: '是否启用' })
  @IsOptional()
  @IsBoolean()
  enable?: boolean;

  @ApiPropertyOptional({ description: '个人信息' })
  @IsOptional()
  profile?: Profile;

  @ApiPropertyOptional({ description: '角色信息' })
  @IsOptional()
  @IsArray()
  roleIds?: number[];
}

/** 修改密码 dto */
export class ChangePasswordDto {
  @IsString()
  @IsNotEmpty({ message: '旧密码不能为空' })
  @ApiProperty({ description: '旧密码' })
  oldPassword: string;

  @IsString()
  @IsNotEmpty({ message: '新密码不能为空' })
  @Length(6, 20, { message: '密码长度必须大于6位小于20位' })
  @ApiProperty({ description: '密码' })
  newPassword: string;
}

/** 更新用户信息 */
export class UpdateUserDto {
  @IsNotEmpty({ message: '用户id不能为空' })
  @ApiProperty({ description: '用户id' })
  id: number;

  @IsString({ message: '用户名必须为字符串' })
  @ApiProperty({ description: '用户名' })
  nickName: string;

  @ApiProperty({ description: '邮箱' })
  @IsEmail({}, { message: '邮箱格式有误' })
  email: string;

  @ApiProperty({ description: '地址' })
  @IsString()
  address: string;

  @ApiProperty({ description: '头像' })
  @IsString()
  avatar: string;
}
